#!/bin/bash
# $Id: echo_wavplay,v 1.3 2004/10/09 02:02:46 repeater Exp $
# $Log: echo_wavplay,v $
# Revision 1.3  2004/10/09 02:02:46  repeater
# Changed forcekey/unkey to normal key/unkey.
#
# Revision 1.2  2004/08/24 23:36:31  repeater
# Added ul conversion for smoother combined audio files.
#
# Revision 1.1  2004/08/03 19:36:36  repeater
# Initial revision
#
###########################################################
#                                                         #                  
#  Released under the GNU Public License                  #                  
#                                                         #                  
#  Script     :  "echo_wavplay                            #
#  Author     :  Marcus Xenakis WA2DCI                    #
#  Version    :  .15 Beta                                 #
#  Date       :  3/28/03                                  #
#  About      :  Plays EchoIRLP wav files                 #
#                                                         #
###########################################################

[ -z "$ECHO_SCRIPT" ] && ECHO_SCRIPT=/home/EchoIRLP/scripts
   source $ECHO_SCRIPT/echo_common

if [ "$#" = "0" ] ; then exit 1; fi
#Converts audio to nice congruent audio, without gaps, if there is more
#than one argument in the script.

if [ -f /usr/bin/sox ] ; then
  while [ -n "$1" ];do
    if [ ! -f $ECHO_AUDIO/$1.ul ] ; then
      rm -f $RUN/temp.ul
      /usr/bin/sox $ECHO_AUDIO/$1.wav $RUN/temp.ul
      cat $RUN/temp.ul >> $RUN/wavefile.ul
    else
      cat $ECHO_AUDIO/$1.ul >> $RUN/wavefile.ul
    fi
    shift
  done
  /usr/bin/sox $RUN/wavefile.ul -s -u $RUN/wavefile.wav
  WAVFILES="$RUN/wavefile.wav"
else
  while [ -n "$1" ] ; do
    WAVFILES="$WAVFILES $ECHO_AUDIO/$1.wav"
    shift
  done
fi

$BIN/coscheck
$BIN/key
# Allows users to set the TXDELAY in the environment file
usleep ${TXDELAY:-250000}
$BIN/play $WAVFILES > /dev/null 2>&1
usleep 250000
$BIN/unkey

rm -f $RUN/temp.ul
rm -f $RUN/wavefile.ul
rm -f $RUN/wavefile.wav

exit 0
